package com.marvin.controller;

import com.marvin.service.IBlogCategoryService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Optional;

/**
 * @author yinyin
 * @create 2021/11/14 下午 6:02
 */
@Controller
public class BlogCategoryController {
    @Autowired
    private IBlogCategoryService blogCategoryService;

    //freemark方式
    @GetMapping(value = {"/","/index"})
    public ModelAndView index(String categoryId,String categoryTitle){
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.addObject("blogCategoryList",blogCategoryService.findBlogCategory());
        modelAndView.addObject("categoryId", Optional.ofNullable(categoryId).orElse("0"));
        modelAndView.addObject("categoryTitle",Optional.ofNullable(categoryTitle).orElse(""));
        modelAndView.setViewName("index");
        return modelAndView;
    }
    @GetMapping("/login")
    public String   toLogin(){
        return "login";
    }

    @GetMapping("demo")
    public String demo(){
        return "indexs";
    }
}
